xlv.obj.ximg={
	extend:function(){
	},
	implement:function(){
		this.implement('xlv.imp.mvc');
	},
	create:function(tag){
		var div=document.createElement('div');
		div.setAttribute('xlvobject','xlv.obj.ximg');
		return div;			
	},
	properties:{
		dmName:null,
		dmPath:null,
		src:null
	},
	method:{
		construct:function(){
		},
		initial:function(){
			if(this.$P.src)this._evalImg(this.$P.src);
		},
		imgSrc:function(src){
			this._evalImg(src);
		},
		_evalImg:function(src){
			this.$V.name=(src||this.$P.src);
			if(this.$V.img) this.removeChild(this.$V.img);
			if(!this.$V.name) return;
			this.$V.image=new Image();
			this.addEventHandler('load','_load',this.$V.image);
			this.$V.image.src=this.$V.name;
		},
		_load:function(){
			this.appendChild(this.$V.img=document.createElement('img'));
			this.style.position='relative';
			this.$V.img.style.display='block';
			this.$V.img.style.position='relative';
			this.$V.img.style.align='center';
			this.$V.img.style.marginLeft='auto';
			this.$V.img.style.marginRight='auto';
			/*
			this.$V.img.style.marginTop='auto';
			this.$V.img.style.marginBottom='auto';
			this.$V.img.style.verticalAlign='middle';
			*/
			var w=this.clientWidth-parseInt(this.style.paddingLeft||0)-parseInt(this.style.paddingRight||0);
			var h=this.clientHeight-parseInt(this.style.paddingTop||0)-parseInt(this.style.paddingBottom||0);
			var iw=this.$V.image.width;
			var ih=this.$V.image.height;
			var factor=1;
			if(iw/w > ih/h)	{
				factor=Math.min(w,iw)/iw;
				this.$V.img.setAttribute('width',Math.min(w,iw)+'px');
			}else {
				factor=Math.min(h,ih)/ih;
				this.$V.img.setAttribute('height',Math.min(h,ih)+'px');
			}
			if(h>ih) {
				//this.$V.img.style.marginTop=((h-ih*factor)/2-1)+'px';
				this.$V.img.style.top=((h-ih*factor)/2-1)+'px';
			}
			this.$V.img.src=this.$V.name;
		},
		/**mvc imp*/
		mvc_valueFromModel:function(dm){
			return this.mvc_isModel(dm) ? dm.getValue(this.$P.dmPath) : null;
		},
		mvc_valueToModel:function(value,dm){
			if(this.mvc_isModel(dm)) dm.setValue(value,this.$P.dmPath);
		},
		mvc_beforeModelChanged:function(model,notify,memo){
		},
		mvc_modelChanged:function(dm,notify,memo){
			if(this.mvc_isModel(dm))this.mvc_valueToView(this.mvc_valueFromModel(dm));
		},
		mvc_valueFromView:function(){
		},
		mvc_valueToView:function(value){
			if(Object.isElement(value)) value=xlv.util.getElementValue(value);
			this.$V.img.src=value;
		}
	}
};
